﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLiSinhVien_v01.BUS.Data;
using QuanLiSinhVien_v01.BUS.Pattern;
using QuanLiSinhVien_v01.DTO;

namespace QuanLiSinhVien_v01.GUI
{
    public partial class FormNhapDiem : Form
    {
        LopHocBus lopHocBus = new LopHocBus();
        SinhVienBus sinhVienBus = new SinhVienBus();
        MonHocBus monHocBus = new MonHocBus();
        BangDiemBus bangDiemBus = new BangDiemBus();
        private LopHocDto[] dsLopHoc;
        private MonHocDto[] dsMonHoc;

        public FormNhapDiem()
        {
            InitializeComponent();
        }

        private void FormNhapDiem_Load(object sender, EventArgs e)
        {
            ObserverMailSender lalala = new ObserverMailSender();
            dsMonHoc = monHocBus.GetList();
            for (int i = 0; i < dsMonHoc.Length; i++)
            {
                cboMonHoc.Items.Add(dsMonHoc[i].TenMonHoc);
            }    
        }

        private void cboLopHoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                SinhVienDto[] dsLop = sinhVienBus.GetList();
                for (int i = 0; i < dsLop.Length; i++)
                {
                    cboMaSV.Items.Add(dsLop[i].MSSV);
                }
            }
            catch (Exception)
            {
            }
        }

        private void cboMaHS_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                sinhVienBus.Info.MSSV = cboMaSV.Text;
                txtHoTen.Text = sinhVienBus.GetSinhVien().HoTen;
            }
            catch (Exception)
            {
            }
            
        }

        private void btnNhap_Click(object sender, EventArgs e)
        {
            BangDiemDto bangDiemDto = new BangDiemDto();
            try
            {
                bangDiemDto.DiemLiThuyet = float.Parse(txtLiThuyet.Text);
                bangDiemDto.DiemThucHanh = float.Parse(txtThucHanh.Text);
                bangDiemDto.DiemKhac = float.Parse(txtKhac.Text);
                bangDiemDto.MaMonHoc = dsMonHoc[cboMonHoc.SelectedIndex].MaMonHoc;
                bangDiemDto.MSSV = cboMaSV.Text;
            //    bangDiemDto.LanThu = Int32.Parse(txtLanThu.Text);
                bangDiemDto.DiemTongKet = (bangDiemDto.DiemLiThuyet*6 + bangDiemDto.DiemThucHanh*4 + bangDiemDto.DiemKhac)/10;
                bangDiemBus.Info = bangDiemDto;
                bangDiemBus.Insert();

                MessageBox.Show("Xong");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi!");
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}

